package com.cn.servlet.news;

import com.cn.Dao.NewsinfoDao;
import com.cn.entity.NewsInfo;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

//import org.apache.commons.dbutils.QueryRunner;

public class NewsListServlet1 extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //准备所有报刊的数据List<Product>
        NewsinfoDao newsinfoDao = new NewsinfoDao();
        List<NewsInfo> newsInfoList = new ArrayList<>();
        try {
            newsInfoList = newsinfoDao.findAll();
            System.out.println("读取报刊成功");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //商品集合准备好
        //将数据存储到request域转发给about.jsp进行显示
        request.setAttribute("newsInfoList", newsInfoList);
        request.getRequestDispatcher("/all_newspaper_admin.jsp").forward(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
